import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { QmsDefect } from "@/pages/qms/defect/entity";

interface MultiDefectSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedDefects: QmsDefect[]) => void;
}

const MultiDefectSelector:React.FC<MultiDefectSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的缺陷
  const [selectedDefects, setSelectedDefects] = useState<QmsDefect[]>([]);

  const handleOk = () => {
		onOk(selectedDefects);
	};

	return (
		<Modal title="选择缺陷" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="defect_selector"
        selectionType={SelectionType.CHECKBOX}
        onSelectChange={(selectedRows) => {setSelectedDefects(selectedRows)}}  
      />
		</Modal>
	);
}

export default MultiDefectSelector;